using System;

namespace SMS.SMPPClient.Common
{
    public class Utils
    {
        // Methods
        private static int char2bin(char ch)
        {
            int num = Convert.ToInt32(ch);
            if ((0x39 >= num) && (num >= 0x30))
                return (num - 0x30);
            
            if ((90 >= num) && (num >= 0x41))
                return ((num - 0x41) + 10);
            
            if ((0x7a >= num) && (num > 0x61))
                num = (num - 0x61) + 10;
            
            return num;
        }

        public static byte[] hex2bin(string hex)
        {
            int length = hex.Length;
            byte[] buffer = new byte[length / 2];
            for (int i = 0; i < length; i += 2)
            {
                int num3 = char2bin(hex[i]);
                int num4 = char2bin(hex[i + 1]);
                buffer[i / 2] = (byte)(((num3 << 4) & 240) | (num4 & 15));
            }
            return buffer;
        }

        public static string[] SplitMessage(string s)
        {
            int num = s.Length / 0xfe;
            if ((s.Length % 0xfe) > 0)
                num++;
            
            string[] strArray = new string[num];
            for (int i = 0; i < num; i++)
            {
                if (i != (num - 1))
                    strArray[i] = s.Substring(i * 0xfe, 0xfe);
                else
                    strArray[i] = s.Substring(i * 0xfe, s.Length - (i * 0xfe));
            }
            return strArray;
        }
    }
}

